import com.live.player.live_player.MyViewFactory;

import org.jetbrains.annotations.Nullable;

import java.util.Map;

import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry.Registrar;
import io.flutter.plugin.common.PluginRegistry;

public class MyAppPlugin implements MethodChannel.MethodCallHandler {
    private Registrar registrar;

    public MyAppPlugin(Registrar registrar) {
        this.registrar = registrar;
    }

    @Override
    public void onMethodCall(MethodCall methodCall, Result result) {
        if (methodCall.method.equals("callNativeFunction")) {
            Map<String, Object> params = methodCall.arguments();
            // 处理传递过来的参数params，进行相关操作
            // 返回结果到Flutter侧
            result.success("Success");
        } else {
            result.notImplemented();
        }
    }

    public static void registerWith(PluginRegistry registry) {
        final String key = MyAppPlugin.class.getCanonicalName();
        if (registry.hasPlugin(key)) return;
        PluginRegistry.Registrar registrar = registry.registrarFor(key);
        registrar.platformViewRegistry().registerViewFactory("com.live.player", new MyViewFactory(registrar.messenger()));
    }

}